package com.koron.order.defect.excel;

import com.alibaba.excel.converters.string.StringStringConverter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.koron.common.core.business.datadict.utils.DataDictTool;

import java.util.Map;

/**
 * @author yijian
 * @since 2022/7/29
 */
public class DefectVOContractConvertor extends StringStringConverter {
    private final Map<String, String> defect;
    private final Map<String, String> major;

    public DefectVOContractConvertor(){
        this.defect = DataDictTool.getDataDictByCode("workorderManagement", "order_defect_status");
        this.major = DataDictTool.getDataDictByCode("publicDictionary", "common_major");
    }

    /**
     *
     * @param value 实际值
     * @param contentProperty 导出的属性实体对象
     * @param globalConfiguration
     * @return
     */
    @Override
    public WriteCellData<String> convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        // 获取属性名
        String fieldName = contentProperty.getField().getName();
        if ("status".equals(fieldName)) {
            value = defect.get(value);
        }
        if ("major".equals(fieldName)){
            value = major.get(value);
        }
        return new WriteCellData<>(value==null?"":value);
    }
}
